package io.renren.modules.task.controller;

import java.util.Arrays;
import java.util.Map;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.task.entity.TaskRecordEntity;
import io.renren.modules.task.service.TaskRecordService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 定时任务记录
 *
 * @author xianwenchao
 * @email 1140617792@qq.com
 * @date 2021-02-15 23:25:36
 */
@RestController
@Api(value = "定时任务记录")
@RequestMapping("task/taskrecord")
public class TaskRecordController {
    @Autowired
    private TaskRecordService taskRecordService;

    /**
     * 定时任务记录列表
     */
    @GetMapping("/list")
    @RequiresPermissions("task:taskrecord:list")
    @ApiOperation(value = "查询定时任务记录列表")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = taskRecordService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 根据id查询定时任务记录信息
     */
    @GetMapping("/info/{id}")
    @RequiresPermissions("task:taskrecord:info")
    @ApiOperation(value = "根据id查询定时任务记录信息")
    public R info(@PathVariable("id") Long id){
		TaskRecordEntity taskRecord = taskRecordService.getById(id);

        return R.ok().put("taskRecord", taskRecord);
    }

    /**
     * 新增定时任务记录记录
     */
    @PostMapping("/save")
    @RequiresPermissions("task:taskrecord:save")
    @ApiOperation(value = "新增定时任务记录记录")
    public R save(@RequestBody TaskRecordEntity taskRecord){
		taskRecordService.save(taskRecord);

        return R.ok();
    }

    /**
     * 根据id修改定时任务记录记录
     */
    @PostMapping("/update")
    @RequiresPermissions("task:taskrecord:update")
    @ApiOperation(value = "根据id修改定时任务记录信息")
    public R update(@RequestBody TaskRecordEntity taskRecord){
		taskRecordService.updateById(taskRecord);

        return R.ok();
    }

    /**
     * 根据id删除定时任务记录记录
     */
    @PostMapping("/delete")
    @RequiresPermissions("task:taskrecord:delete")
    @ApiOperation(value = "根据id删除定时任务记录记录(非逻辑删除，建议不使用)")
    public R delete(@RequestBody Long[] ids){
		taskRecordService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
